package base.render;

import java.awt.Graphics2D;
import java.util.Random;

import base.Start;
import base.living.ILiving;
import base.world.World;

public abstract class Render implements ILiving
{
	private int tickCounter;
	private int tickSpeed = 1;
	
	protected Random rand = new Random();
	
	public Render()
	{
		
	}
	
	protected void onTickUpdate()
	{
		this.setNextTick(rand.nextInt(100) + 50);
	}
	
	public void onUpdate()
	{
		this.tickCounter -= tickSpeed;
		if (shouldTickUpdate())
		{
			onTickUpdate();
		}
	}
	
	public void onPreRender(Graphics2D par1Graphics)
	{
		
	}
	
	public void onRender(Graphics2D par1Graphics)
	{
		
	}
	
	public void onDestroy() {}
	
	private void setNextTick(int par1)
	{
		this.tickCounter = par1;
	}
	
	private boolean shouldTickUpdate()
	{
		return this.tickCounter <= 0;
	}
	
	public void setTickSpeed(int par1)
	{
		this.tickSpeed = par1 <= 150 ? par1 : 150;
	}
	
	public World getWorldObj()
	{
		return (World) Start.theWorld;
	}
}
